package com.hzw.saas.web.app.product.controller;


import java.util.ArrayList;
import java.util.List;
import javax.annotation.Resource;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hzw.saas.api.product.IProductService;
import com.hzw.saas.api.product.dto.ProductDto;
import com.hzw.saas.api.product.enums.ProductCloudType;
import com.hzw.saas.api.property.IPropertyService;
import com.hzw.saas.api.property.bo.PropertyBO;
import com.hzw.saas.api.property.enmus.SysDictKeyEnum;
import com.hzw.saas.api.property.enmus.SysDictModuleEnum;
import com.hzw.saas.common.config.util.PageParam;
import com.hzw.saas.web.app.product.dto.ExprCloudMenuDto;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiOperationSort;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;

/**
 * <p>
 * 体验云 前端控制器
 * </p>
 *
 * @author sonam
 * @since 2021-01-19
 */
@RestController
@RequestMapping
@RequiredArgsConstructor
@Api(tags = "产品中心/体验云")
public class ExprCloudController {

    private final IProductService productService;

    @Resource(name = IPropertyService.SYS_DICT_BEAN)
    private final IPropertyService<SysDictKeyEnum> propertyService;

    @GetMapping("/cloud/expr/menu")
    @ApiOperation(value = "获取体验云分类菜单")
    @ApiOperationSort(0)
    public ResponseEntity<List<ExprCloudMenuDto>> getVideoTypeMenuList() {
        List<PropertyBO> sysPropertyBOS = propertyService.listProperties(SysDictModuleEnum.PRODUCT_SUB_TYPE.getModule());
        List<ExprCloudMenuDto> exprCloudMenuDtos = new ArrayList<>();

        sysPropertyBOS.forEach(sysPropertyBO -> {
            ExprCloudMenuDto exprCloudMenuDto = new ExprCloudMenuDto();
            exprCloudMenuDto.setMenuId(sysPropertyBO.getKey());
            exprCloudMenuDto.setMenuName(sysPropertyBO.getValue());
            exprCloudMenuDtos.add(exprCloudMenuDto);
        });

        return ResponseEntity.ok(exprCloudMenuDtos);
    }

    @GetMapping("/cloud/expr")
    @ApiOperation(value = "获取体验云活动/产品列表", notes = "根据分类菜单获取体验云活动列表")
    @ApiOperationSort(1)
    public ResponseEntity<IPage<ProductDto>> getProductVideoList(PageParam pageParam, @ApiParam(value = "体验云分类：0-鸿之微云，1-软件计算，2-工具使用，3-数据助力")
    @RequestParam(required = false) Integer subType) {
        IPage<ProductDto> productList = productService.searchByCouldTypeAndSubTypePage(pageParam, ProductCloudType.EXP_CLOUD.value(), subType);
        return ResponseEntity.ok(productList);
    }


}
